package com.wyw.learning.thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 练习newFixedThreadPool
 *
 * @author Mr Wu    yewen.wu.china@gmail.com
 * @date 2021/7/4   5:29 下午
 * <p>
 * Update History:
 * Author        Time            Content
 */
public class FixedThreadPoolTest {

    public static void main(String[] args) {
        ExecutorService executorService =
                Executors.newFixedThreadPool(4);
        //无界队列，一旦一个出错，或者阻塞，将会出现OOM异常情况
        for (int i = 0; i<1000 ;i++){
            executorService.execute(new Task());
        }

    }
}

class Task implements Runnable{

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName());
    }
}
